package Estrutura;
import bd.*;
import com.mysql.jdbc.PreparedStatement;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import java.lang.String;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import org.apache.jasper.tagplugins.jstl.core.Catch;
import tipadas.*;


public class cadastraCliente {

    Conexao bd = new Conexao();

public void conecta(){
    bd.conectar(Conf_BD.driver, Conf_BD.url_BD,Conf_BD.usuario, Conf_BD.senha);

}

public Vector getCliente(){
    conecta();
    Vector vet = new Vector();
    ResultSet rs= bd.consulta("select * from cliente;");
    try{
        while(rs.next()){
            cliente cli= new cliente();
            cli.setCodigo(rs.getInt("codigo"));
            cli.setNome(rs.getString("nome"));
            cli.setEndereco(rs.getString("endereco"));
            vet.addElement(cli);
        }
        }catch(Exception e){}
            bd.desconectar();
            return vet;

        }

public cliente getCliente(int codigo){
    conecta();
    ResultSet rs = bd.consulta ("SELECT * FROM cliente Where codigo = "+codigo+";");
   cliente cl = new cliente();

     try{
      while(rs.next()){
        cl.setCodigo (rs.getInt ("codigo"));
        cl.setNome(rs.getString ("nome"));
        cl.setEndereco(rs.getString ("endereco"));

      }
     }catch(Exception x){}
    bd.desconectar();
     return cl;
  }
    
public String insereCliente( String nome, String endereco){
        conecta();
        String resp = bd.tratDados ("INSERT INTO `cliente` (`nome`, `endereco`) VALUES ('"+nome+"', '"+endereco+"');");
        bd.desconectar();
        return resp;
}


}
